package com.jinzhi.jzweb;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@EnableScheduling
@Slf4j
public class TestScheduled {



    public static void main(String[] args) {
        //直接初始化
        SesaonEnum season1 = SesaonEnum.SPRING;
        //调用SeasonEnum枚举类的getChinese()方法获取SPRING的中文值
        System.out.println(season1.getChinese());

    }


    /**
     */
    //每30秒执行
   // @Scheduled(cron="*/3 * * * * ?")
    //0 0/1 * * * ?//每9分钟执行
    //   @Scheduled(cron="0 0/9 * * * ?")
    // public void teamReturn() {
    //发放代理返点
    public   void   teamAddMoney(){

        System.out.println("执行定时任务");
        timeffc();
    }


    public void timeffc() {

        HttpURLConnection conn = null;
        float Max = 1, Min = 0;

        //System.out.println("nextTime="+masssp.get("nextTime").toString()+"当前时间="+sdf.format(new Date()));
        if (1==1) {
            System.out.println("进来了判断执行抓取数据=================");
            try {
                String url = "http://www.tx-ffc.com/info-kj/" ;
                URL realUrl = new URL(url);
                conn = (HttpURLConnection) realUrl.openConnection();
                conn.setRequestMethod("GET");
                conn.setUseCaches(false);
                conn.setReadTimeout(8000);
                conn.setConnectTimeout(8000);
                conn.setInstanceFollowRedirects(false);
                conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0");
                int code = conn.getResponseCode();
                if (code == 200) {
                    InputStream is = conn.getInputStream();
                    BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                    StringBuffer buffer = new StringBuffer();
                    String line = "";
                    while ((line = in.readLine()) != null) {
                        buffer.append(line);
                    }
                    String result = buffer.toString();
                    System.out.println("result="+result);

                    String txtcontent = result.replaceAll("</?[^>]+>", ""); //剔出<html>的标签
                    txtcontent = txtcontent.replaceAll("<a>\\s*|\t|\r|\n</a>", "");//去除字符串中的空格,回车,换行符,制表符
                    txtcontent= txtcontent.replaceAll("&nbsp;","").replaceAll("期号","").replace(" ","").replace("开奖时间","").replace("开奖号码","")
                            .replace("大小","") .replace("单双","").replace("和值","").replace("和值","").replace("龙虎","").replace("前三","")
                            .replace("中三","").replace("后三","");
                    String txffc= txtcontent.substring(0,23);

                     System.out.println("txtcontent"+txtcontent);
                    System.out.println("分割数据="+txffc);
                   String  time=txffc.substring(0,5);
                    String  time1=txffc.substring(5,9);
                    String  time2=txffc.substring(9,14);
                    String  qihao=txffc.substring(14,18);
                    String  haoma=txffc.substring(18,23);
                    String  haomasss=txffc.substring(0,9);
                    System.out.println("分割时间="+time+"-"+time1.substring(0,2)+"-"+time1.substring(2,4)+" "+time2+":00");
                    System.out.println("haomasss="+haomasss);
                    //subscriber是观察者，在本代码中可以理解成发送数据给activity
                    // subscriber.onNext(result);
                }else {
                    System.out.println("状态异常="+code);
                }
            } catch (Exception e) {
                e.printStackTrace();
                // subscriber.onError(e);
            }
        }
    }
}
